Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve e2e HostExec utility #84444

Merged
merged 1 commit into from Oct 30, 2019
Merged

Improve e2e HostExec utility #84444

merged 1 commit into from Oct 30, 2019

Conversation

cofyc
Copy link
Member

@cofyc cofyc commented Oct 28, 2019

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespace from that line:

/kind api-change
/kind bug

/kind cleanup

/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake

What this PR does / why we need it:

  • add a method to return detail result:
    • separate stdout and stderr
    • command exit code
  • remove kubectl dependency

Which issue(s) this PR fixes:

Fixes #84233

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 28, 2019
@k8s-ci-robot k8s-ci-robot added area/test sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 28, 2019
// This works like ssh.SSH(...) utility.
func (h *hostExecutor) Execute(cmd string, node *v1.Node) (Result, error) {
result, err := h.exec(cmd, node)
if codeExitErr, ok := err.(exec.CodeExitError); ok {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e2elog.Logf("exec %s: command: %s", remote, result.Cmd)
e2elog.Logf("exec %s: stdout: %q", remote, result.Stdout)
e2elog.Logf("exec %s: stderr: %q", remote, result.Stderr)
e2elog.Logf("exec %s: exit code: %d", remote, result.Code)
Copy link
Member Author

@cofyc cofyc Oct 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like ssh.LogResult, here are some examples:

Oct 28 19:14:21.053: INFO: exec k8s-testing-worker: command:   ls -1 /mnt/disks/by-uuid/google-local-ssds-scsi-fs/ | wc -l
Oct 28 19:14:21.053: INFO: exec k8s-testing-worker: stdout:    "0\n"
Oct 28 19:14:21.053: INFO: exec k8s-testing-worker: stderr:    "ls: cannot access '/mnt/disks/by-uuid/google-local-ssds-scsi-fs/': No such file or directory\n"
Oct 28 19:14:21.053: INFO: exec k8s-testing-worker: exit code: 0

failed command log:

Oct 28 18:59:52.926: INFO: exec k8s-testing-worker: command:   ls -1 /mnt/disks/by-uuid/google-local-ssds-scsi-fs/
Oct 28 18:59:52.926: INFO: exec k8s-testing-worker: stdout:    ""
Oct 28 18:59:52.926: INFO: exec k8s-testing-worker: stderr:    "ls: cannot access '/mnt/disks/by-uuid/google-local-ssds-scsi-fs/': No such file or directory\n"
Oct 28 18:59:52.926: INFO: exec k8s-testing-worker: exit code: 2

// HostExec represents interface we require to execute commands on remote host.
type HostExec interface {
Execute(cmd string, node *v1.Node) (Result, error)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New method to replace ssh.SSH.

- separate stdout and stderr
- return command exit code
- remove kubectl dependency
@cofyc
Copy link
Member Author

cofyc commented Oct 28, 2019

/priority important-soon
/assign @msau42

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 28, 2019
@@ -1182,9 +1182,10 @@ func validateStatefulSet(config *localTestConfig, ss *appsv1.StatefulSet, anti b
// and skips if a disk of that type does not exist on the node
func SkipUnlessLocalSSDExists(config *localTestConfig, ssdInterface, filesystemType string, node *v1.Node) {
ssdCmd := fmt.Sprintf("ls -1 /mnt/disks/by-uuid/google-local-ssds-%s-%s/ | wc -l", ssdInterface, filesystemType)
res, err := config.hostExec.IssueCommandWithResult(ssdCmd, node)
res, err := config.hostExec.Execute(ssdCmd, node)
utils.LogResult(res)
Copy link
Member Author

@cofyc cofyc Oct 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as an example usage of Execute method. I didn't remove all IssueCommand/IssueCommandWithResult use cases. These two methods are simple to use sometimes.

e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
)

// Result holds the execution result of remote execution command.
type Result struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like ssh.Result except no User field

@cofyc
Copy link
Member Author

cofyc commented Oct 28, 2019

/retest

result := Result{
Host: node.Name,
Cmd: cmd,
}
pod, ok := h.nodeExecPods[node.Name]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember @jsafrane hit some issue with creating two host exec pods in the same test. Did that ever get resolved? How about hostexec for two tests running in parallel?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It had been resolved. Originally, it used a static pod name. If a test has two instances of HostExec, pod names will conflict. @jsafrane switched to use GenerateName to avoid pod name conflict here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A limitation is this utility cannot be shared by multiple parallel tests. We can add support when necessary.

@msau42
Copy link
Member

msau42 commented Oct 29, 2019

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 29, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cofyc, msau42

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 29, 2019
@k8s-ci-robot k8s-ci-robot merged commit 345bea9 into kubernetes:master Oct 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

e2e: better HostExec
3 participants